package com.aop.controller;


import com.aop.domain.entity.OperationLog;
import com.aop.service.IOperationLogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.common.ano.Log;
import com.common.dto.OperationLogDTO;
import com.common.vo.Result;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 操作日志表 前端控制器
 * </p>
 *
 * @author 坤哥
 * @since 2025-10-11
 */
@RestController
@RequestMapping("/operation-log")
@Slf4j
public class OperationLogController {
    @Resource
    private IOperationLogService operationLogService;

    /**
     * 保存操作日志
     */
    @PostMapping("/saveLog")
    public void saveLog(@RequestBody OperationLogDTO operationLog) {
        log.info("保存操作日志: {}", operationLog);
        operationLogService.saveLog(operationLog);
    }

    /**
     * 查询日志列表（分页）
     */
    @GetMapping("/list")
    public Result<IPage<OperationLog>> getLogList(
            @RequestParam(required = false) String userName,
            @RequestParam(required = false) String operationType,
            @RequestParam(required = false) String operationModule,
            @RequestParam(required = false) String status,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        log.info("查询日志列表: userName={}, operationType={}, operationModule={}, status={}, startTime={}, endTime={}, pageNum={}, pageSize={}",
                userName, operationType, operationModule, status, startTime, endTime, pageNum, pageSize);
        
        IPage<OperationLog> page = operationLogService.getLogList(
                userName, operationType, operationModule, status, 
                startTime, endTime, pageNum, pageSize
        );
        
        return Result.ok(page);
    }
}
